<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title> 首 页 </title>
  <!-- 依 赖 样 式 -->
  <link rel="stylesheet" th:href="@{component/pear/css/pear.css}"/>
  <!-- 加 载 样 式-->
  <link rel="stylesheet" th:href="@{admin/css/load.css}"/>
  <!-- 布 局 样 式 -->
  <link rel="stylesheet" th:href="@{admin/css/admin.css}"/>
  <link rel="icon" href="admin/images/favicon.ico" type="image/x-icon"/>
  <style>
    .layui-nav-tree .layui-nav-item > a .layui-nav-more {
      padding: 0 0;
    }

    .pear-admin .layui-logo img {
      height: 34px !important;
      width: auto !important;
    }

    .pear-admin .layui-logo .title {
      top: 2px !important;
      margin-left: -7px !important;
    }
  </style>
</head>
<!-- 结 构 代 码 -->
<body class="layui-layout-body pear-admin">
<!-- 布 局 框 架 -->
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <!-- 顶 部 左 侧 功 能 -->
    <ul class="layui-nav layui-layout-left">
      <li class="collaspe layui-nav-item"><a href="#" class="layui-icon layui-icon-shrink-right"></a></li>
      <li class="refresh layui-nav-item"><a href="#" class="layui-icon layui-icon-refresh-1" loading=600></a></li>
    </ul>
    <!-- 顶 部 右 侧 菜 单 -->
    <div id="control" class="layui-layout-control"></div>
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item layui-hide-xs">
        <a href="#" class="fullScreen layui-icon layui-icon-screen-full"></a>
      </li>
      <!-- pear 官网 -->
      <!-- <li class="layui-nav-item layui-hide-xs"><a href="http://www.pearadmin.com" class="layui-icon layui-icon-website"></a></li> -->
      <!-- 消息 -->
      <!-- <li class="layui-nav-item layui-hide-xs message"></li> -->
      <li class="layui-nav-item user">
        <!-- 头 像 -->
        <a href="javascript:;">
          <!-- <img src="admin/images/avatar.jpg" class="layui-nav-img"> -->
          <img src="" class="layui-nav-img" style="display:none;">
        </a>
        <!-- 功 能 菜 单 -->
        <dl class="layui-nav-child">
          <!-- <dd><a user-menu-url="view/system/person.html" user-menu-id="5555" user-menu-title="基本资料">基本资料</a></dd> -->
          <dd><a href="javascript:void(0);" class="change">修改密码</a></dd>
          <dd><a href="javascript:void(0);" class="logout">注销登录</a></dd>
        </dl>
      </li>
      <!-- 主 题 配 置 -->
      <li class="layui-nav-item setting"><a href="#" class="layui-icon layui-icon-more-vertical"></a></li>
    </ul>
  </div>
  <!-- 侧 边 区 域 -->
  <div class="layui-side layui-bg-black">
    <!-- 菜 单 顶 部 -->
    <div class="layui-logo">
      <!-- 图 标 -->
      <img class="logo" style="">
      <!-- 标 题 -->
      <span class="title" style="color: #a4da3b !important;"></span>
    </div>
    <!-- 菜 单 内 容 -->
    <div class="layui-side-scroll">
      <div id="sideMenu"></div>
    </div>
  </div>
  <!-- 视 图 页 面 -->
  <div class="layui-body">
    <!-- 内 容 页 面 -->
    <div id="content"></div>
  </div>
  <!-- 遮 盖 层 -->
  <div class="pear-cover"></div>
  <!-- 加 载 动 画-->
  <!-- 加 载 动 画 去 除 -->
  <!--  <div class="loader-main">-->
  <!--    <div class="loader"></div>-->
  <!--  </div>-->
</div>
<!-- 移 动 端 便 捷 操 作 -->
<div class="pear-collasped-pe collaspe">
  <a href="#" class="layui-icon layui-icon-shrink-right"></a>
</div>
<div class="changePwd" style="display: none">
  <div class="layui-card">
    <div class="layui-card-body">
      <form class="layui-form" action="">
        <div class="layui-form-item">
          <label class="layui-form-label">旧密码</label>
          <div class="layui-input-block">
            <input type="password" name="oldpwd" required lay-verify="required" placeholder="请输入"
                   autocomplete="off"
                   class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">新密码</label>
          <div class="layui-input-block">
            <input type="password" name="newpwd" required lay-verify="required" placeholder="请输入"
                   autocomplete="off"
                   class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">再次输入新密码</label>
          <div class="layui-input-block">
            <input type="password" name="newpwd2" required lay-verify="required" placeholder="请输入"
                   autocomplete="off"
                   class="layui-input">
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
<!-- 依 赖 脚 本 -->
<script th:src="@{component/layui/layui.js}"></script>
<script th:src="@{component/pear/pear.js}"></script>
<script th:src="@{component/my/const.js}"></script>
<!-- 框 架 初 始 化 -->
<script>
  layui.use(['admin', 'jquery', 'convert', 'popup'], function () {
    var admin = layui.admin;
    var $ = layui.jquery;
    var convert = layui.convert;
    var popup = layui.popup;

    $.ajax({
      url: suffix + "/admin/info",
      dataType: 'json',
      type: 'get',
      success: function (res) {
        if (res.code == 0) {
          // 初始化顶部用户信息
          // admin.setAvatar("admin/images/avatar.jpg", "admin");
          admin.setAvatar("", res.data.name)
        }
      }
    })
    // 根目录下 pear.config.yml 文件为初始化配置
    // 你可以通过 admin.setConfigPath 方法修改配置文件位置
    // 你可以通过 admin.setConfigType 方法修改配置文件类型
    admin.setConfigType("yml");
    admin.setConfigPath("config/pear.config.yml");
    admin.render();

    // 登出逻辑
    admin.logout(function () {
      $.ajax({
        url: suffix + '/admin/logout',
        type: 'get',
        dataType: 'json',
        success: function (res) {
          if (res.code == 0) {
            popup.success("注销成功", function () {
              location.href = "login";
            })
          } else {
            popup.failure(res.msg);
          }
        }
      })
      // 注销逻辑 返回 true / false
      return true;
    })


    $(".change").click(function () {
      var se = layer.open({
        type: 1,
        content: $(".changePwd"),
        btn: ['确定', '取消'],
        yes: function (index, layero) {
          if ($("input[name='newpwd']").val() != $("input[name='newpwd2']").val()) {
            layer.msg("新密码两次输入不一致");
            $("input[name='newpwd2']").val("")
            return false;
          }
          $.ajax({
            url: suffix + "/admin/change",
            dataType: 'json',
            data: {
              oldpwd: $("input[name='oldpwd']").val(),
              newpwd: $("input[name='newpwd']").val()
            },
            type: 'post',
            success: function (result) {
              if (result.code == 0) {
                layer.close(se)
                layer.msg(result.msg, {
                  icon: 1,
                  time: 700
                }, function () {
                  location.href = "login";
                });
              } else {
                layer.msg(result.msg, {
                  icon: 2,
                  time: 700
                });
              }
            }
          })
        },
        btn2: function (index, layero) {
        },
        end: function () {

        }
      });
    })


    // 初始化消息回调
    admin.message();

    // 重写消息回调 [消息列表点击事件]
    // admin.message(function(id, title, context, form) {});

  })
</script>
</body>
</html>
